package com.CampusLife.controller;

import  com.CampusLife.bean.ProductComment;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import  com.CampusLife.service.IProductCommentService;
import  com.CampusLife.until.DataTime;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
@Controller
@RequestMapping("/ProductComment")
public class ProductCommentController {
    @Resource
    private IProductCommentService iProductCommentService;
    @RequestMapping("/queryAll")
    public  String  findall(Model model){
        List<ProductComment> productComments=iProductCommentService.queryAll();
        model.addAttribute("productComments",productComments);
        return  "/home.jsp";
    }
    //用户发表评论
    @RequestMapping("/add")
    public String addcomment(String comment_txt, int pid, HttpSession httpSession, Model model){
        ProductComment productComment=new ProductComment();
       productComment.setComment_txt(comment_txt);
        int i=(int) httpSession.getAttribute("id");
       productComment.setId(i);
       productComment.setPid(pid);
         DataTime dataTime=new DataTime();
        String data=dataTime.gettime();
        productComment.setTime(data);
        iProductCommentService.add(productComment);
        return "";
    }
    //展示评论
    @RequestMapping("/ByLostid")
    public  String ByLostid(Integer pid,Model model){
        List<ProductComment> productComments= iProductCommentService.queryById(pid);
        model.addAttribute("productComments",productComments);
        return "";
    }
    //删除评论
    @RequestMapping("/delete")
    public  String delete(Integer cid){
        iProductCommentService.delete(cid);
        return "";
    }
}
